package cn.zsb.printer;

/**
 * @author oldliu
 * @since 1.0
 */
public class TextPaper {
    private int words;//一行打几个字
    private int lines;//一张纸能打几行

    public void print(String str) {
        char[] cr = str.toCharArray();
        //w是当前行打了几个字，l是当前页打了几行，p是当前是第几页
        int w = 0, l = 0, p = 0;
        for (char c : cr) {
            System.out.print(c);
            w++;
            if (w >= words) {
                l++;
                w = 0;
                System.out.println();
                if (l >= lines) {
                    p++;
                    l = 0;
                    System.out.println("--" + p + "--");//页码
                }
            }
        }
        if (w > 0 || l > 0) {
            System.out.println("\n--" + (++p) + "--");//页码
        }
    }

    public void setWords(int words) {
        this.words = words;
    }

    public void setLines(int lines) {
        this.lines = lines;
    }

    public int getWords() {
        return words;
    }

    public int getLines() {
        return lines;
    }
}
